package com.lw.lost.daos

import android.content.ContentValues
import android.database.Cursor
import android.database.sqlite.SQLiteDatabase

class MatchRecordDao(private val db: SQLiteDatabase) {
    
    fun insert(userId: Long, matchedUserId: Long): Long {
        val values = ContentValues().apply {
            put("userId", userId)
            put("matchedUserId", matchedUserId)
        }
        return db.insert("match_records", null, values)
    }

    fun getMatchRecordsByUserId(userId: Long): Cursor {
        return db.rawQuery(
            """
            SELECT * FROM match_records 
            WHERE userId = ? OR matchedUserId = ?
            ORDER BY matchTime DESC
            """,
            arrayOf(userId.toString(), userId.toString())
        )
    }

    // 删除好友关系
    fun deleteMatch(userId1: Long, userId2: Long): Int {
        return db.delete(
            "match_records",
            "(userId = ? AND matchedUserId = ?) OR (userId = ? AND matchedUserId = ?)",
            arrayOf(userId1.toString(), userId2.toString(), userId2.toString(), userId1.toString())
        )
    }
} 